package com.ruoyi.huanghefd.controller;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.huanghefd.domain.LimitWorkApproveSheet;
import com.ruoyi.huanghefd.service.LimitWorkApproveSheetService;
import com.ruoyi.huanghefd.utils.PageBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author gnplum
 * @Date 2024/12/3 17:51
 * @PackageName:com.ruoyi.huanghefd.controller
 * @ClassName: LimitWorkApproveSheetController
 * @Description: 有限作业审批单操作
 * @Version 1.0
 */
@RestController
@RequestMapping("/huanghefd")
public class LimitWorkApproveSheetController {
    private static final Logger log = LoggerFactory.getLogger(LimitWorkApproveSheetController.class);

    @Resource
    private LimitWorkApproveSheetService limitWorkApproveSheetService;

    @PostMapping("/addLimitWorkApproveSheet")
    public AjaxResult addLimitWorkApproveSheet(@RequestBody LimitWorkApproveSheet limitWorkApproveSheet) {
        log.info(">> 新增有限作业审批单-入参==" + JSON.toJSONString(limitWorkApproveSheet));
        AjaxResult ajax = limitWorkApproveSheetService.addLimitWorkApproveSheet(limitWorkApproveSheet);
        log.info("<< 新增有限作业审批单-返回==" + ajax.toString());
        return ajax;
    }

    @PostMapping("/delLimitWorkApproveSheet")
    public AjaxResult delLimitWorkApproveSheet(@RequestParam(required = false, value = "lsCode") String lsCode) {
        log.info(">> 删除有限作业审批单-入参 lsCode==" + lsCode);
        if(lsCode.isEmpty()){
            return AjaxResult.success("请点选要删除的工作票");
        }
        AjaxResult ajax = limitWorkApproveSheetService.delLimitWorkApproveSheet(lsCode);
        log.info(">> 删除有限作业审批单-返回==" + ajax);
        return ajax;
    }

    @PostMapping(value = "/uptLimitWorkApproveSheet")
    public AjaxResult uptLimitWorkApproveSheet(@RequestBody LimitWorkApproveSheet limitWorkApproveSheet) {
        log.info(">> 修改有限作业审批单-入参 ==" + JSON.toJSONString(limitWorkApproveSheet));
        AjaxResult ajax = limitWorkApproveSheetService.uptLimitWorkApproveSheet(limitWorkApproveSheet);
        log.info(">> 修改有限作业审批单-返回 ==" + ajax);
        return ajax;
    }

    @PostMapping(value = "/queryLimitWorkApproveSheet")
    public PageBean queryLimitWorkApproveSheet(
            @RequestParam(required = false, value = "lsCode") String lsCode,
            @RequestParam(required = false, value = "lsDept") String lsDept,
            @RequestParam(required = false, value = "lsState") String lsState,
            @RequestParam(required = false, value = "userId") String userId,
            @RequestParam(required = false, value = "mailType") String mailType,//mailType 1-收件箱 2-发件箱 3-草稿箱
            @RequestParam(value = "pageNum") int pageNum,
            @RequestParam(value = "pageSize") int pageSize) {
        log.info(">> 查询有限作业审批单-入参==" + lsCode + "," + lsDept + "," + lsState + "," + userId + "," + mailType);
        PageBean ajax = limitWorkApproveSheetService.queryLimitWorkApproveSheetByPage(lsCode, lsDept, lsState, userId, mailType, pageNum, pageSize);//mailType 1-收件箱 2-发件箱 3-草稿箱
        log.info(">> 查询有限作业审批单-返回==" + ajax);
        return ajax;
    }
}